<template>
  <div>
    <el-dialog title="车辆信息" :visible.sync="show" width="70%" append-to-body>
      <div>
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="80px"
          @submit.native.prevent
        >
          <el-form-item label="名称/账号" prop="keyWord">
            <el-input
              v-model="queryParams.keyWord"
              placeholder="请输入人员名称或手机号"
              maxlength="11"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            >
              搜索
            </el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
              重置
            </el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
        </el-row>
        <el-table v-loading="loading" :data="dataList" border stripe>
          <el-table-column label="#" type="index" width="55" align="center">
            <template slot-scope="scope">
              <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="车辆照片" align="center" width="140">
            <template slot-scope="scope">
              <div v-if="scope.row.vehicleImgUrl">
                <el-image
                  :src="baseUrl + scope.row.vehicleImgUrl"
                  :preview-src-list="[baseUrl + scope.row.vehicleImgUrl]"
                  style="width: 100px; height: 50px"
                />
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="车牌号"
            align="center"
            prop="vehicleNumber"
            width="120"
          />
          <el-table-column label="品牌" align="center" prop="vehicleBrand" width="120" />
          <el-table-column label="用户名称" align="center">
            <template slot-scope="scope">
              {{ scope.row.realName || scope.row.nickName || "-" }}
            </template>
          </el-table-column>
          <el-table-column label="手机号" align="center" prop="userName" />
          <el-table-column label="用户类型" align="center" width="120">
            <template slot-scope="scope">
              <el-tag
                :type="
                  scope.row.memberType == 1
                    ? 'success'
                    : scope.row.memberType == 2
                    ? 'warning'
                    : 'info'
                "
                effect="plain"
              >
                {{
                  scope.row.memberType == 1
                    ? "充电/停车"
                    : scope.row.memberType == 2
                    ? "停车"
                    : "临时用户"
                }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="充电卡号" align="center" prop="cardNo" />
          <el-table-column
            label="充电类型"
            align="center"
            prop="vehicleChargeTypeValue"
            width="120"
          />
          <el-table-column
            label="非充电类型"
            align="center"
            prop="vehicleNonChargeTypeValue"
            width="120"
          />
          <el-table-column label="用户类型" align="center" width="120">
            <template slot-scope="scope">
              <el-tag
                :type="
                  scope.row.vipType == 1
                    ? 'warning'
                    : scope.row.vipType == 2
                    ? 'danger'
                    : scope.row.vipType == 3
                    ? 'success'
                    : 'info'
                "
                effect="plain"
              >
                {{
                  scope.row.vipType == 1
                    ? "月卡会员"
                    : scope.row.vipType == 2
                    ? "季卡会员"
                    : scope.row.vipType == 3
                    ? "年卡会员"
                    : "非会员"
                }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="停车点位" align="center" prop="areaName" />
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleCancel">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listVehicle } from "@/api/weiriya/vehicle";
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    // 停车点位ID
    id: {
      type: String,
      default: "",
    },
  },
  computed: {
    show: {
      get() {
        return this.value;
      },
      set() {
        this.$emit("input", false);
      },
    },
  },
  watch: {
    value(val) {
      if (val) {
        this.queryParams.areaId = this.id;
        this.getList();
      }
    },
  },
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      loading: false, // 加载状态
      showSearch: true, // 显示搜索条件
      dataList: [], // 数据列表
      total: 0, // 总条数
      // 查询参数
      queryParams: {
        keyWord: null, // 关键字
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  methods: {
    // 获取数据
    getList() {
      this.loading = true;
      listVehicle(this.queryParams)
        .then((res) => {
          this.dataList = res.rows;
          this.total = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 搜索
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 关闭弹窗
    handleCancel() {
      this.show = false;
    },
  },
};
</script>

<style lang="scss" scoped></style>
